﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Users;

namespace University.Workshop.Presentation.Users
{
    /// <summary>
    /// Interaction logic for ChangePassword.xaml
    /// </summary>
    public partial class ChangePassword : Page, IModifyUserPasswordView
    {
        MainWindow mw;
        PresenterModifyUserPassword pModifyPerson;
        bool nuevo;

        public ChangePassword(Model.User user, MainWindow mW)
        {
            mw = mW;

            if ((user.Login).Equals(user.Password) && !((user.Login).Equals("admin")))
                nuevo = true;
            else
                nuevo = false;


            InitializeComponent();
            pModifyPerson = new PresenterModifyUserPassword(this, user);
        }

        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            pModifyPerson.UpdateViewData();
            App.Current.MainWindow.Title = "Cambiar Contraseña";
        }

        public void SystemMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Atencion!!!", MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }

        public void ErrorMessage(string MessageValue)
        {
            MessageBox.Show(App.Current.MainWindow, MessageValue, "Error!!!", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, MessageBoxOptions.RightAlign);
        }




        #region IModifyUserPasswordView Members


        public string Login
        {
            set 
            {
                LoginLbl.Content = value;
            }
        }

        public string OldPassword
        {
            get 
            {
                return OldPasswordTxt.Password;
            }
        }


        public string NewPassword
        {
            get 
            {
                return NewPasswordTxt.Password;
            }
        }

        public string RetryPassword
        {
            get 
            {
                return RetypePasswordTxt.Password;
            }
        }

        #endregion


        private void CancelBtn_Click(object sender, RoutedEventArgs e)
        {
            //this.NavigationService.Navigate(new Users.SearchUser());
            this.Visibility = System.Windows.Visibility.Collapsed;
            
            if (nuevo)
                mw.salirSistema();
            //else

        }

        private void ModifyBtn_Click(object sender, RoutedEventArgs e)
        {
            bool seModifico;

            seModifico = pModifyPerson.UpdatePerson();

            if (seModifico)
            {
                MessageBox.Show("La contraseña fue modificada exitosamente. Ingrese nuevamente al sistema.");
                //this.NavigationService.Navigate(new Users.SearchUser());
                this.Visibility = System.Windows.Visibility.Hidden;
                mw.salirSistema();
            }
        }


        private void PersonNamesTxt_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
            }
        }

        private void CantCupyPasteOrCut(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Copy)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Cut)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Paste)
                e.Handled = true;
        }
    }
}
